//
//  OrganizationCell.m
//  easystudy
//
//  Created by kane on 15/6/8.
//  Copyright (c) 2015年 kane. All rights reserved.
//

#import "OrganizationCell.h"

@implementation OrganizationCell
@synthesize logoImgView,orgNameLabel,descLabel,addressLabel;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        logoImgView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 79, 79)];
        [self.contentView addSubview:logoImgView];
        
        orgNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(92, 5, 220, 20.0)];
        orgNameLabel.backgroundColor = [UIColor clearColor];
        orgNameLabel.textColor = [UIColor blackColor];
        orgNameLabel.font = [UIFont boldSystemFontOfSize:14.0];
        [self.contentView addSubview:orgNameLabel];
        
        descLabel = [[UILabel alloc] initWithFrame:CGRectMake(92, 25, 220, 15)];
        descLabel.font = [UIFont systemFontOfSize:12.0];
        descLabel.textColor = [UIColor grayColor];
        descLabel.backgroundColor = [UIColor clearColor];
        descLabel.numberOfLines = 0;
        [self.contentView addSubview:descLabel];
        
        addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(92, 42, 220.0, 15)];
        addressLabel.textAlignment = NSTextAlignmentLeft;
        addressLabel.font = [UIFont systemFontOfSize:12.0];
        addressLabel.textColor = [UIColor grayColor];
        addressLabel.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:addressLabel];
        
        starView = [[UIView alloc] initWithFrame:CGRectMake(92, 62, 120, 20)];
        [self.contentView addSubview:starView];
        
        for (int i = 0; i < 5; i++) {
            UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(i * 21, 0, 20, 20)];
            imgView.tag = 10+i;
            [starView addSubview:imgView];
        }
    }
    
    return self;
}

- (void)setOrgStars:(float)stars
{
    int a = stars * 10;
    int b = a / 10;
    BOOL half = a % 10 > 0;
    
    for (int i = 0; i < 5; i++) {
        UIImageView *imgView = (UIImageView *)[starView viewWithTag:10+i];
        if (i < b) {
            imgView.image = [UIImage imageNamed:@"organ_star02"];
        }else if (i == b && half){
            imgView.image = [UIImage imageNamed:@"organ_star03"];
        }else{
            imgView.image = [UIImage imageNamed:@"organ_star01"];
        }
    }
}

@end
